<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ taglib uri="http://java.sun.com/jsp/jstl/fmt" prefix="fmt" %>
<%@ page language="java" contentType="text/html; charset=UTF-8"
         pageEncoding="UTF-8" %>
<%@include file="/WEB-INF/jsp/common/navigationRight.jsp" %>
<%@include file="/WEB-INF/jsp/common/head.jsp" %>
<%@include file="/WEB-INF/jsp/common/navigationLeft.jsp" %>




<style>
    .m2-manageResult-item td{
        white-space: nowrap;
        overflow: hidden;
        text-overflow: ellipsis;
        max-width: 180px;
    }
    .m2-manageResult-head th{
        white-space: nowrap;
    }
</style>

<div class="m2-userPrizerecord-con">
    <div class="m2-userPrizerecord-head">
        <h3><i></i>我的奖励金记录</h3>
        <a href="#" style="display: none;"></a>
    </div>
    <div class="m2-userCentermanage-accNum">
        <div class="m2-userCentermanage-accNumlef">
            <p class="m2-userCentermanage-accNumtit">
                <span>激活奖励金（元）</span>
                <b class="m2-userCentermanagedraw-moreDetail">
                    <u style="top:-10px;line-height:26px;">
                        <em style="top:8px" class="m2-draw-arr"></em>
                        <em style="top:8px" class="m2-draw-arrBg"></em>
                        奖励金激活部分，投资即可使用
                    </u>
                </b>
            </p>
            <p class="m2-userCentermanage-accNum-leave">${couldUseReward}</p>
        </div>
        <div class="m2-userCentermanage-accNumrig">
            <p class="m2-userCentermanage-accNumtit">
                <span>待激活奖励金（元）</span>
                <b class="m2-userCentermanagedraw-moreDetail">
                    <u>
                        <em class="m2-draw-arr"></em>
                        <em class="m2-draw-arrBg"></em>
                        奖励金待激活部分，元老会成员专享，项目结清时即可激活
                    </u>
                </b>
            </p>
            <p class="m2-userCentermanage-accNum-return">${canNotUseReward}</p>
        </div>
    </div>

    <div class="m2-manage-search">
        <div class="m2-manage-search-head">
            <h3><i></i>奖励金流水记录</h3>
        </div>


        <div class="m2-manage-search-selector">
            <ul class="m2-manageSearchsel-time">
                <li>时间范围：</li>
                <li class="m2-manageSearchsel-link"><span class="m2-manSealink-sel" onclick="displayAll()" data-days='1000000'>全部</span></li>
                <li class="m2-manageSearchsel-link"><span class="m2-manSealink-unsel" onclick="displayAll()" data-days='7'>最近7天</span></li>
                <li class="m2-manageSearchsel-link"><span class="m2-manSealink-unsel" onclick="displayAll()" data-days='30'>一个月</span></li>
                <li class="m2-manageSearchsel-link"><span class="m2-manSealink-unsel" onclick="displayAll()" data-days='90'>三个月</span></li>
                <li>从<input id="m2-manSeadate-start" type="text"></li>
                <li>到<input id="m2-manSeadate-end" onblur="searchDate()" type="text"></li>
            </ul>
            <ul class="m2-manageSearchsel-type">
                <li>资金类型：</li>
                <li class="m2-manageSearchsel-link"><span class="m2-manSealink-sel" onclick="displayAll()" data-status="3">全部</span></li>
                <li class="m2-manageSearchsel-link"><span class="m2-manSealink-unsel" onclick="displayAll()" data-status="1">未激活</span></li>
                <li class="m2-manageSearchsel-link"><span class="m2-manSealink-unsel" onclick="displayAll()" data-status="2">已激活</span></li>
            </ul>

            <table class="m2-manageResult" cellpadding="0" cellspacing="0">
                <tr class="m2-manageResult-head">
                    <th style="width:120px;">时间</th>
                    <th style="width:155px;">资金类型</th>
                    <th style="width:135px;">描述</th>
                    <th style="width:120px;">个数</th>

                </tr>
                <c:forEach items="${listReward}" var="AqbReward">
                <tr class="sp-foreach">
                        <td style="width:120px;">${AqbReward.getAndMoveTime}</td>
                        <td style="width:155px;">
                            <c:if test="${AqbReward.rewardType eq 0}">未激活</c:if>
                            <c:if test="${AqbReward.rewardType eq 1}">已激活</c:if>
                            <c:if test="${AqbReward.rewardType eq 2}">已使用</c:if>
                        </td>
                        <td style="width:135px;">${AqbReward.describe}</td>
                        <td style="width:120px;">
                            <c:if test="${AqbReward.amount eq 0}">${AqbReward.usedReward}</c:if>
                            <c:if test="${AqbReward.amount != 0}">${AqbReward.amount}</c:if>
                        </td>

                </tr>
                </c:forEach>
                <tr class="m2-manageResult-head">
                    <th style="width:100px;">剩余可用个数:${surplus}(个)</th>
                </tr>
            </table>
            <%--<div class="page-bar">--%>
                <%--<ul class="page-num-ul clearfix">--%>
                    <%--<li>共<span class="zyf-totalCount"></span>条记录&nbsp;&nbsp; <span class="zyf-currentPageNo"></span>/<span class="zyf-totalPageCount"></span> 页</li>--%>
                    <%--<a class="zyf-first">首页</a>--%>
                    <%--<a class="zyf-prev">上一页</a>--%>
                    <%--<a class="zyf-second">下一页</a>--%>
                    <%--<a class="zyf-last">最后一页</a>--%>
                    <%--&nbsp;&nbsp;--%>
                <%--</ul>--%>
                <%--<span class="page-go-form"><label>跳转至</label>--%>
             <%--<input type="text" name="inputPage" id="inputPage" class="page-key" />页--%>
             <%--<button type="button" class="page-btn" onClick='jump_to(document.getElementById("inputPage").value)'>GO</button>--%>
            <%--</span>--%>
            <%--</div>--%>
        </div>
    </div>



</div>

</div>
<script type="text/javascript">


    var start = 1;
    var status = 3;
    var time1 = '';
    var time2 = '';
    var pages = 3;
    var days = 0;

    // 显示一段时间的奖励金
    <%--function searchDate(){--%>
        <%--var status = $(".m2-manage-search-selector .m2-manSealink-sel").attr("status")--%>
        <%--var begin = $("#m2-manSeadate-start").val();--%>
        <%--var end = $("#m2-manSeadate-end").val();--%>
        <%--$.ajax({--%>
            <%--"url":"/reward/rewardList",--%>
            <%--"type":"post",--%>
            <%--"dataType":"json",--%>
            <%--"data":{"status":status,"begin":begin,"end":end},--%>
            <%--"success":function (data) {--%>
                <%--if(0 == status ){--%>
                    <%--var listReward = $(data.listReward);--%>
                    <%--var cgstr="";--%>
                    <%--listReward.each(function () {--%>
                        <%--var date = getMyDate(this.getAndMoveTime);--%>
                        <%--cgstr += "<tr>"--%>
                        <%--cgstr += "<td style=\"width:120px;\">${AqbReward.getAndMoveTime}</td>"--%>
                        <%--cgstr += "<td style=\"width:155px;\">"--%>
                        <%--cgstr += "<c:if test="${AqbReward.rewardType eq 0}">未激活</c:if>"--%>
                        <%--cgstr += "<c:if test="${AqbReward.rewardType eq 1}">已激活</c:if>"--%>
                        <%--cgstr += "<c:if test="${AqbReward.rewardType eq 2}">已使用</c:if>"--%>
                        <%--cgstr += "</td>"--%>
                        <%--cgstr += "<td style=\"width:135px;\">${AqbReward.describe}</td>"--%>
                        <%--cgstr += "<td style=\"width:120px;\">"--%>
                        <%--cgstr += "<c:if test="${AqbReward.amount eq 0}">${AqbReward.usedReward}</c:if>"--%>
                        <%--cgstr += "<c:if test="${AqbReward.amount != 0}">${AqbReward.amount}</c:if>"--%>
                        <%--cgstr += "</td>"--%>
                        <%--cgstr += "</tr>"--%>
                    <%--})--%>
                    <%--cgstr += "<tr class=\"m2-manageResult-head\">"--%>
                    <%--cgstr += "<th style=\"width:100px;\">剩余可用个数:${surplus}  (个)</th>"--%>
                    <%--cgstr += "</tr>"--%>
                    <%--$(".m2-manageResult-sum").html("");--%>
                    <%--$(".m2-manageResult-head").after(cgstr);--%>
                <%--}else if(1 == status){--%>
                    <%--var CreditorList1 = $(data.CreditorList1);--%>
                    <%--var cgstr="";--%>
                    <%--CreditorList1.each(function () {--%>
                        <%--var date = getMyDate(this.transferTime);--%>
                        <%--cgstr += "<tr class='m2-manageResult-sum'>"--%>
                        <%--cgstr += "<th style='width:200px;'>"+this.proName+"</th>"--%>
                        <%--cgstr += "<th style='width:100px;'>"+this.currentRate+"</th>"--%>
                        <%--cgstr += "<th style='width:120px;'>"+this.subscribeMoney+"</th>"--%>
                        <%--cgstr += "<th style='width:120px;'>"+this.transferMonry+"</th>"--%>
                        <%--cgstr += "<th style='width:180px;'>"+date+"</th>"--%>
                        <%--cgstr += "<th style='width:120px;'>"+this.currentMoney+"</th>"--%>
                        <%--cgstr += "</tr>"--%>
                    <%--})--%>

                    <%--$(".m2-manageResult-sum").html("");--%>
                    <%--$(".m2-manageResult-head").after(cgstr);--%>
                <%--}else if(2 == status){--%>
                    <%--var CreditorList2 = $(data.CreditorList2);--%>
                    <%--var cgstr="";--%>
                    <%--CreditorList2.each(function () {--%>
                        <%--var date = getMyDate(this.modifyDate);--%>
                        <%--cgstr += "<tr class='m2-manageResult-sum'>"--%>
                        <%--cgstr += "<th style='width:200px;'>"+this.proName+"</th>"--%>
                        <%--cgstr += "<th style='width:100px;'>"+this.subscribeMoney+"</th>"--%>
                        <%--cgstr += "<th style='width:100px;'>"+this.transferMonry+"</th>"--%>
                        <%--cgstr += "<th style='width:100px;'>"+this.getRate+"</th>"--%>
                        <%--cgstr += "<th style='width:150px;'>"+date+"</th>"--%>
                        <%--cgstr += "</tr>"--%>
                    <%--})--%>

                    <%--$(".m2-manageResult-sum").html("");--%>
                    <%--$(".m2-manageResult-head").after(cgstr);--%>
                <%--}else if(3 == status){--%>
                    <%--var receptList = $(data.receptList);--%>
                    <%--var cgstr="";--%>
                    <%--receptList.each(function () {--%>
                        <%--var date = getMyDate(this.receptTime);--%>
                        <%--cgstr += "<tr class='m2-manageResult-sum'>"--%>
                        <%--cgstr += "<th style='width:200px;'>"+this.proName+"</th>"--%>
                        <%--cgstr += "<th style='width:100px;'>"+this.receptMoney+"</th>"--%>
                        <%--cgstr += "<th style='width:100px;'>"+this.currentRate+"</th>"--%>
                        <%--cgstr += "<th style='width:150px;'>"+date+"</th>"--%>
                        <%--cgstr += "<th style='width:100px;'>"+this.restDay+"</th>"--%>
                        <%--cgstr += "</tr>"--%>
                    <%--})--%>

                    <%--$(".m2-manageResult-sum").html("");--%>
                    <%--$(".m2-manageResult-head").after(cgstr);--%>
                <%--}--%>

            <%--} ,--%>
            <%--"error":function (e) {--%>
                <%--alert(e.toString());--%>
            <%--}--%>
        <%--});--%>

    <%--}--%>

    //显示一段时间的奖励金流水
    function searchDate() {
        var rewardType = $(".m2-manageSearchsel-type .m2-manSealink-sel").attr("data-status");
        var begin = $("#m2-manSeadate-start").val();
        var end = $("#m2-manSeadate-end").val();
        $.ajax({
            "url":"/reward/rewardListss",
            "type":"post",
            "dataType":"json",
            "data":{"rewardType":rewardType,"begin":begin,"end":end},
            "success":function (data) {
                if(null != data ){
                    var listReward = $(data.listRewardByZore);
                    var cgstr="";
                    listReward.each(function () {
                        var date = getMyDate(this.getAndMoveTime);
                        cgstr += "<tr class='sp-foreach'>"
                        cgstr += "<td style=\"width:120px;\">" + date + "</td>"
                        cgstr += "<td style=\"width:155px;\">"
                        if(this.rewardType == 0){
                            cgstr += "未激活";
                        }
                        if(this.rewardType == 1){
                            cgstr += "已激活";
                        }
                        if(this.rewardType == 2){
                            cgstr += "已使用";
                        }
                        cgstr += "</td>"
                        cgstr += "<td style=\"width:135px;\">"+this.describe+"</td>"
                        cgstr += "<td style=\"width:120px;\">"
                        if(this.amount == 0){
                            cgstr += this.usedReward;
                        }
                        if(this.amount != 0){
                            cgstr += this.amount;
                        }
                        cgstr += "</td>"
                        cgstr += "</tr>"
                    })
                    $(".sp-foreach").remove();
                    $(".m2-manageResult-head:first").after(cgstr);
                }
            } ,
            "error":function (e) {

            }
        });
    }


    //根据时间显示奖励金流水
    function displayAll() {

        var rewardType = $(".m2-manageSearchsel-type .m2-manSealink-sel").attr("data-status");
        var rewardDays = $(".m2-manageSearchsel-time .m2-manSealink-sel").attr("data-days");
        $.ajax({
            "url":"/reward/rewardLists",
            "type":"post",
            "dataType":"json",
            "data":{"rewardType":rewardType,"startDay":rewardDays},
            "success":function (data) {
                if(null != data ){
                    var listReward = $(data.listRewardByZore);
                    var cgstr="";
                    listReward.each(function () {
                        var date = getMyDate(this.getAndMoveTime);
                        cgstr += "<tr class='sp-foreach'>"
                        cgstr += "<td style=\"width:120px;\">" + date + "</td>"
                        cgstr += "<td style=\"width:155px;\">"
                        if(this.rewardType == 0){
                            cgstr += "未激活";
                        }
                        if(this.rewardType == 1){
                            cgstr += "已激活";
                        }
                        if(this.rewardType == 2){
                            cgstr += "已使用";
                        }
                        cgstr += "</td>"
                        cgstr += "<td style=\"width:135px;\">"+this.describe+"</td>"
                        cgstr += "<td style=\"width:120px;\">"
                        if(this.amount == 0){
                            cgstr += this.usedReward;
                        }
                        if(this.amount != 0){
                            cgstr += this.amount;
                        }
                        cgstr += "</td>"
                        cgstr += "</tr>"
                    })
                    $(".sp-foreach").remove();
                    $(".m2-manageResult-head:first").after(cgstr);
                }
            } ,
            "error":function (e) {
                alert("ajax错误")
            }
        });
    }

    //时间转换
    function getMyDate(str){
        var oDate = new Date(str),
            oYear = oDate.getFullYear(),
            oMonth = oDate.getMonth()+1,
            oDay = oDate.getDate(),
            oTime = oYear +'-'+ getzf(oMonth) +'-'+ getzf(oDay);//最后拼接时间
        return oTime;
    };

    function getzf(num){
        if(parseInt(num) < 10){
            num = '0'+num;
        }
        return num;
    }

    $(document).ready(function(){
        //加载初始数据
        getRewordRecord();
        //加载日历
        ucDatepicker('#m2-manSeadate-start','usercenter-rewardcontrol-getRewardLogAjax',getSearchData,processData);
        ucDatepicker('#m2-manSeadate-end','usercenter-rewardcontrol-getRewardLogAjax',getSearchData,processData);
        //时间过滤按钮
        $('.m2-manageSearchsel-time span').click(function(){
            $('#m2-manSeadate-start').val('');
            $('#m2-manSeadate-end').val('');
            time1 = '';
            time2 = '';
            days = $(this).data('days');
            clear();
            getRewordRecord();
            $('.m2-manageSearchsel-time span.m2-manSealink-sel').addClass('m2-manSealink-unsel');
            $('.m2-manageSearchsel-time span.m2-manSealink-sel').removeClass('m2-manSealink-sel');
            $(this).removeClass('m2-manSealink-unsel');
            $(this).addClass('m2-manSealink-sel');
        });
        //状态过滤按钮
        $('.m2-manageSearchsel-type span').click(function(){
            status = $(this).data('status');
            clear();
            getRewordRecord();
            $('.m2-manageSearchsel-type span.m2-manSealink-sel').addClass('m2-manSealink-unsel');
            $('.m2-manageSearchsel-type span.m2-manSealink-sel').removeClass('m2-manSealink-sel');
            $(this).removeClass('m2-manSealink-unsel');
            $(this).addClass('m2-manSealink-sel');
        });
        //加载更多按钮
        $('.m2-manageResult-more').click(function(){
            getRewordRecord();
        });
    });
    getRewordRecord(0,1,3);
    function getRewordRecord(days,status,currentPageNo){

        $.ajax({
            url:"/reward/show",
            type:"POST",
            data:{
                time1:time1,
                time2:time2,
                days:days,
                currentPageNo:currentPageNo,
                status:status,
                start:start
            },
            dataType:'json',
            success:function(data){
                processData(data);
                $(".m2-userCentermanage-accNum-leave").html(data.canUse)
            }
        });
    }

    function processData(data){
        obj = eval('('+data+')');
        start++;
        pages = obj['pages'];
        checkBtn();
        showData(obj['data']);
    }

    function showData(obj){

        if(obj){
            var sum = Number($('#sum_reward').text());
            for(var i in obj){
                var tr = '<tr class="m2-manageResult-item">';
                tr += '<td>'+obj[i]['date']+'</td>';
                tr += '<td>'+obj[i]['type_text']+'</td>';
                tr += '<td title="'+obj[i]['info']+'">'+obj[i]['info']+'</td>';
                if(obj[i]['affect_money']>=0){
                    tr += '<td class="m2-manageResultitem-up">';
                }else{
                    tr += '<td class="m2-manageResultitem-down">';
                }
                tr += +obj[i]['affect_money']+'</td>';
                tr += '<td>'+obj[i]['reward_money']+'</td>';
                tr += '<td>'+(obj[i]['sum_inactive']?obj[i]['sum_inactive']:0)+'</td>';
                tr += '</tr>';
                $('.m2-manageResult-sum').before(tr);
                sum = calPlus(sum,obj[i]['affect_money']);
            }
            $('#sum_reward').text(sum);
            if(sum < 0){
                $('#sum_reward').css('color','#E64648');
            }else{
                $('#sum_reward').css('color','#717171');
            }
        }
        if($('.m2-manageResult-item').size() == 0){
            $('.m2-manageResult-sum').before('<tr class="m2-manageResult-item"><td colspan="6">暂无数据</td></tr>');
            $('.m2-manageResult-sum').hide();
        }
    }

    function getSearchData(){
        clear();
        days = 0;
        time1 = $('#m2-manSeadate-start').val();
        time2 = $('#m2-manSeadate-end').val();
        $('.m2-manageSearchsel-time span.m2-manSealink-sel').addClass('m2-manSealink-unsel');
        $('.m2-manageSearchsel-time span.m2-manSealink-sel').removeClass('m2-manSealink-sel');
        if(!time1 && !time2){
            $('.m2-manageSearchsel-time span').eq(0).addClass('m2-manSealink-sel');
        }
        var data = {
            time1:time1,
            time2:time2,
            days:days,
            status:status,
            start:start
        };
        return data;
    }

    function checkBtn(){
        if(start > pages){
            $('.m2-manageResult-more').hide();
        }
    }

    function clear(){
        start = 1;
        $('.m2-manageResult-item').remove();
        $('#sum_reward').text('0.00');
        $('#sum_reward').css('color','#717171');
        $('.m2-manageResult-more').show();
    }

    function calPlus(num1,num2){
        var sq1,sq2,m;
        try{sq1=num1.toString().split(".")[1].length;} catch(e){sq1=0;}
        try{sq2=num2.toString().split(".")[1].length;} catch(e){sq2=0;}
        m=Math.pow(10,Math.max(sq1,sq2));
        return Math.round(( num1 * m + num2 * m ) / m * 100)/100;
    }

    function ucDatepicker(locator,url,datafunc,callback){
        $(locator).datetimepicker({
            lang:'ch',
            timepicker:false,
            format:'Y-m-d',
            allowBlank:true,
            onChangeDateTime:function(){
                if(time1 != $('#m2-manSeadate-start').val() || time2 != $('#m2-manSeadate-end').val()){
                    $.ajax({
                        type: "POST",
                        url: url,
                        dataType: 'json',
                        data:datafunc(),
                        success: function(data) {
                            callback(data);
                        }
                    });
                }
            }
        });
    };

    // $(".m2-manSealink-sel").click(function () {
    //     var status = $(this).attr("data-status");
    //      alert(status);
    // });

</script>
</body>
</html>